<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib uri="/struts-tags" prefix="s"%>
<script type="text/javascript" charset="utf-8"
	src="js/jquery.listnav.min-2.1.js"></script>
<script type="text/javascript" charset="utf-8"
	src="js/jquery.dataTables.listnav.js"></script>
<script type="text/javascript" charset="utf-8">
	$(document)
			.ready(
					function() {
						var oTable = $('#organisation-table')
								.dataTable(
										{
											"sDom" : 'Zrtp',
											"sPaginationType" : "bootstrap",
											"iDisplayLength" : 15,
											"bServerSide" : true,
											"bPaginate" : true,
											"sAjaxSource" : "organisationTableAjax.action",
											"aoSearchCols": [
								 				null,
								 				null,
								 				null,
								 				null,
								 				{"sSearch": "Yes"}
								 			],
											"aoColumnDefs" : [ {
												"fnRender" : function(o, val) {
													if (o.aData[4] == "Yes") {
														return '<a href=editOrganisation.action?organisationId=' + o.aData[5] + '>' + o.aData[0] + '</a>';													
													} else {
														return '<a href="#" onClick=toActive(' + o.aData[5] + ')>' + o.aData[0] + '</a>';
													}
												},
												"aTargets" : [0]
											} ]
										});						
						
						$('#check-active').click(function() {
							var other = $('#check-active:checked').val();
							if (other != undefined) {
								oTable.fnFilter("", 4, true, false);
							} else {
								oTable.fnFilter("Yes", 4, true, false);
							}
						});	
						
						var save = getURLParameter('save');
						if (save == "successful") {							
							$.jGrowl("<h4 class='alert-heading'>Save Successfully</h4>", {theme : 'save-notification'});
						}
					});
	function toActive(id) {
		var r = confirm('Do you want to make this Organization active?');
		if (r == true) {
			window.location.replace("activeOrganisation.action?organisationId=" + id);
		}
	}
	
	function getURLParameter(name) {
	    return decodeURI(
	        (RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]
	    );
	}
</script>
<s:if test="#session.logged != 'true'">
	<jsp:forward page="../index.jsp" />
</s:if>
<div class="container-fluid">
	<div class="content">
		<div class="row-fluid">
			<div class="span12">
				<div class="box">
					<div class="box-head">
						<h3>Organisation List</h3>
					</div>
					<div id="organisation" class="box-content">
						<form action="#" class='form-horizontal' method="post">							
							<div class="control-group">
								<div id="inactive-div">
									<a href="addOrganisation.action" class="btn btn-success">Create</a> <label
										class="checkbox"><input type="checkbox"
										name="check-inactive" id="check-active"> Include
										In-active</label>
								</div>
								<table id="organisation-table"
									class="table table-striped table-bordered">
									<thead>
										<tr>
											<th>Organisation Name</th>
											<th>Head Office Address Line 1</th>
											<th>Postcode</th>
											<th>Contact</th>
											<th>Is Active?</th>
										</tr>
									</thead>
									<tbody>
									</tbody>
								</table>
							</div>
						</form>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>